/*
day250
2020.5.4
*/ 
#include<vector>
#include<cstdlib>
#include<cmath>
using namespace std;


struct TreeNode {
    int val;
	TreeNode *left;
    TreeNode *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

class Solution {
public:
    int maxProduct(TreeNode* root) {
		vector<int> vec;
		int M=pow(10,9)+7;
		int sum=help(root,vec);
		int cut_value=sum,min=sum;
		for(int i=0;i<vec.size();++i)
		{
			int tem=abs(sum-vec[i]*2);
			if(tem<min)
			{
				min=tem;
				cut_value=sum-vec[i];
			}
		}
		
		
		return (long long) cut_value*(sum-cut_value)  % M;
    }
    
    int help(TreeNode* root,vector<int> &vec)
    {
    	if(!root)
    	{
    		return 0;
		}
		
		int res=root->val+help(root->left,vec)+help(root->right,vec);
    	vec.push_back(res); 
    	return res;
	}
};


int main()
{
	return 0;
}
